/*
 * @Author: your name
 * @Date: 2021-12-25 15:02:05
 * @LastEditTime: 2021-12-25 16:40:38
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \json-serveg:\桌面2\50htmljs\movie\script.js
 */
const movieUrl = 'https://api.wmdb.tv/api/v1/top?type=Imdb&skip=0&limit=50&lang=Cn'
const main = document.getElementById('main')
 
getMovies(movieUrl)


async function getMovies(url){
    let res = await fetch(url)
    // console.log(res)
    let result = await res.json()
    // console.log(result)
    showMovies(result)
}

function showMovies(movies){
    main.innerHTML = ''
    movies.forEach(item => {
        
        const movieEl =  document.createElement('div')
        movieEl.classList.add('movie')
        console.log(item)
        movieEl.innerHTML = `
        <img src="${item.data[0].poster}" alt="${item.data[0].genre}">
            <div class="movie-info">
        <h3>${item.alias}</h3>
        <span class="${getClassByRate(item.doubanRating)}">${item.doubanRating}</span>
            </div>
            <div class="overview">
        <h3>Overview</h3>
        ${item.data[0].description}
        </div>
        `
        main.appendChild(movieEl)
    });

}

//动态评分
function getClassByRate(vote){
    if (vote >= 8) {
        return 'green'
    } else if (vote >= 5) {
        return 'orange'
    }else{
       return 'red'  
    }
}


